package com.lsh.oms.worker.service.task;

import com.dangdang.ddframe.job.api.JobExecutionMultipleShardingContext;
import com.dangdang.ddframe.job.plugin.job.type.dataflow.AbstractIndividualThroughputDataFlowElasticJob;
import com.lsh.base.trace.id.filter.TraceIdSetter;
import com.lsh.oms.core.model.order.OrderHead;
import com.lsh.oms.core.service.order.OrderDeliveryService;
import com.lsh.oms.core.service.order.OrderQueryService;
import com.lsh.oms.core.service.other.ShippingOrderService;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 订单提交OFC
 *
 * @author huangdong
 * @date 17/1/8
 */
@Component
@Slf4j
@Deprecated
public class OrderAllEsTask extends AbstractIndividualThroughputDataFlowElasticJob<OrderHead> implements InitializingBean {

    private final Logger logger = LoggerFactory.getLogger(this.getClass());
    @Autowired
    private OrderQueryService orderQueryService;

    @Autowired
    private OrderDeliveryService orderDeliveryService;

    @Autowired
    private ShippingOrderService shippingService;

    @Override
    public void afterPropertiesSet() throws Exception {
    }


    @Override
    public List<OrderHead> fetchData(JobExecutionMultipleShardingContext context) {
        TraceIdSetter.set();
        logger.info("订单dealEs fetchData start...");
        List<OrderHead> list = this.orderQueryService.findListByStatusRange(22, 96, 1569924000,1582560000);
        logger.info("订单dealEs fetchData size=" + list.size());

        return list;
    }

    @Override
    public boolean processData(JobExecutionMultipleShardingContext context, OrderHead model) {

        Long orderCode = model.getOrderCode();
        try {

            orderDeliveryService.dealEs(model);
            return true;
        } catch (Throwable t) {
            logger.error("订单添加es processData(" + orderCode + ") end... 提交错误. error message:" + t.getMessage());

        }

        return false;

    }





}
